﻿#region Using namespaces

using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data.SQLite;
using System.Linq;
using System.Text;

using BOL.Apps.GeneNetworkBrowser.Properties;

#endregion

namespace BOL.Apps.GeneNetworkBrowser.Databases
{
    [Database]
    public class GeneRelations_Human : DataContext
    {
        public GeneRelations_Human()
            : base(new SQLiteConnection(Settings.Default.GeneRelations_Human)) { }

        public Table<RelationDBTypes> RelationDBTypes;
        public Table<RelationDBs> RelationDBs;
        public Table<Relations> Relations;
        public Table<Scores> Scores;
    }

    [Table]
    public class RelationDBTypes
    {
        [Column]
        public int ID { get; set; }
        [Column]
        public string Name { get; set; }
    }

    [Table]
    public class RelationDBs
    {
        [Column]
        public int ID { get; set; }
        [Column]
        public string Name { get; set; }
        [Column]
        public int TypeID { get; set; }
    }

    [Table]
    public class Relations : IEquatable<Relations>
    {
        [Column]
        public int SourceID { get; set; }
        [Column]
        public int TargetID { get; set; }
        [Column]
        public uint Pattern { get; set; }

        #region IEquatable<Relation> implementation

        public bool Equals(Relations other)
        {
            return SourceID.Equals(other.SourceID) && TargetID.Equals(other.TargetID) && Pattern.Equals(other.Pattern);
        }

        #endregion

        #region Object overriden

        public override int GetHashCode()
        {
            return SourceID.GetHashCode() ^ SourceID.GetHashCode() ^ (int)Pattern;
        }

        public override bool Equals(object obj)
        {
            if (obj == null) return base.Equals(obj);

            if (!(obj is Relations))
                throw new InvalidCastException("The 'obj' argument is not a Relation object.");
            else
                return Equals(obj as Relations);
        }

        public override string ToString()
        {
            return String.Format("{0}-{1}", SourceID, TargetID);
        }

        #endregion
    }

    [Table]
    public class Scores
    {
        [Column]
        public uint Pattern { get; set; }
        [Column]
        public double Score { get; set; }
    }
}
